<?php
/**
 * 首页
 *
 */
class index extends control {
	/**
	 * 默认首页
	 */
	public function index_action() {
		global $_G;

		//获取所有的项目
		$this->load_model('subject');
		$subjects = $this->model->getSubjects();

		if(isset($_G['pathinfo'][0]) && $_G['pathinfo'][0]) {
			$key = $_G['pathinfo'][0];
			$defaultSubject = $this->model->getSubjectByKey($key, true);
		} else {
			$defaultSubject = $this->model->getSubjectByKey(false, true);
		}

		//获取上次的同步记录
		$synFiles = '';
		if($defaultSubject) {
			$dir = $defaultSubject['dir'];
			$synFiles = $this->model->getSyncFiles($dir);
		}

		$this->assign('subjects', $subjects);
		$this->assign('subject', $defaultSubject);
		$this->assign('sync_files', $synFiles);

		$this->display('index');
	}
}